MODULE PARAMETERS

Implicit NONE 

Integer, Parameter :: dd = Selected_real_kind(15,307)

Integer, Parameter :: I_treat_Mcaid=0 ! set this equal to 1 to allow all those who qualify for Medicaid to get treated. Set to 0 otherwise.
Integer, Parameter :: I_state_fix=3  ! fixed productivity types 
Integer, Parameter :: I_state_ht=2 ! latent health types 

Integer, Parameter :: I_death=1  ! indicator equal to 1 if we allow for a one time cost of death
Integer, Parameter :: I_EPHI=1   ! presence of employer provided health insurance

Integer, Parameter :: n_experiments=60  
Real (Kind=dd), Parameter :: cat_ME=3.846153846d0 

Integer :: I_sd_earn, I_s, I_du, I_dp, I_init_H, I_init_R, I_sick_days, I_wages_health, I_disutil_health, I_good_H, I_good_R, I_EPHI_all, I_EPHI_none, I_med_exp, I_med_exp_s, I_med_exp_du, I_med_exp_dp, I_Col_R, I_Col_H, I_Col_dp , I_med_exp_G, I_sd_HC, I_MEcat

Real (Kind=dd), dimension (2)::  param_calib 

Real (Kind=dd) :: copay_hi 
Real (Kind=dd) :: copay_phi  
Real (Kind=dd) :: premium_phi  

Real (Kind=dd) :: treat_age_adj ! parameter to adjust probability of "can't treat" set for uninsrued at older ages
Real (Kind=dd), dimension (3):: c_floor_age_adj_young
Real (Kind=dd), dimension (3):: c_floor_age_adj_old


!Demographics 
Integer, Parameter :: n_e=3        !There are 3 education groups: 1 = HS dropouts & HS Graduate, 2= some college; 3= college graduate
Integer, Parameter :: n_age=76     !This is the max age to which a person lives (1=25, 76=100)   ( 26=50)
Integer, Parameter :: n_ret= 41      !Everybody retires at age 65 (41=65) 

Integer, Parameter :: n_hc=39   
Real (Kind=dd), dimension (0:n_hc):: HK
Integer, Parameter :: n_hc_grid=5     !This is the max number of grid points for human capital, for any age. (more grid points for older ages)
Integer, parameter :: n_sample=15000  !The number of individuals simulated

!Employment offers
Integer, Parameter :: n_o=5        !1=no offer, 2=PT, no ins, 3=PT, ins, 4=FT, no ins, 5=FT, ins
Integer, Parameter :: n_os=2  ! spouse's employment: 1=not work, 2=work 

!Number of income groups 
Integer, Parameter :: n_inc=5

! options regarding treatment and paying for it
Integer, Parameter :: n_trpay=3 ! 1 = pay and get treated; 2=don't pay, get treated; 3=don't pay, not treated.
Real (Kind=dd), dimension (3,n_o,3,n_ret-1) ::  Shock_type ! (1=cannot treat, 2= can treat, but no default, 3=must treat, can default); second argument is for insurance; third argument is H 
! 1 = you only have options  trpay = 1 or 3 
! 2 = you have all 3 options
! 3= you only have options 1 and 2. 

!Assets and savings
Real (Kind=dd), Parameter :: gridcurv=3.3d0        !Grid for assets (curvature)
Integer, Parameter :: n_sav=11     !number of grid points for savings
Integer, Parameter :: n_sav_sim=74  ! in the simulation, we use a finer grid for savings
Integer, Parameter :: n_as=12        !number of grid points for assets (other than period savings). This is what you carry to next period.

Real (Kind=dd), dimension (n_o, n_sav) :: sav !Discrete choice set for savings while working -- depend on offers. When there is no employment offer, you cannot save too much.
Real (Kind=dd), dimension (n_sav) :: sav_ret  !Discrete choice set for savings while retired -- mostly dissave
Real (Kind=dd), dimension (n_sav) :: sav_grid

Real (Kind=dd), dimension (n_sav_sim) :: sav_sim
Real (Kind=dd), dimension (n_sav_sim) :: sav_grid_sim

! marriage
Integer, Parameter :: n_mar=2
 
  ! initial assets
 Real (Kind=dd), dimension (n_e):: assets_initial
         
! H, R, health shocks, medical expenditures, investments, etc
Integer, Parameter :: n_DI=2      !1- no DI; 2- has DI
Integer, Parameter :: n_h=3       !Number of health states: ranges from 1-3: 1=poor, 2=fair, 3=good 
Integer, Parameter :: n_r=2       !Number of risk factor states: 1=low risk, 2=high risk
Integer, Parameter :: n_du=2      !du : 1= no shock, 2=get a du shock
Integer, Parameter :: n_dp=2      !dp : 1= no shock, 2=get a dp shock
Integer, Parameter :: n_s=2       !s : 1= no shock, 2=get an s shock
Integer, Parameter :: n_ht=2      !latent health types. 1=good , 2= Bad latent type
Integer, Parameter :: n_type1=18  !Grid for educ x permanent productivity type x permanent "healthy type" (3x3x2)
Integer, Parameter :: n_type2=8   !Grid for du x dp x s  (all possible combinations of health shocks)
Integer, Parameter :: n_type3=6   !Grid for HxR 
!Wages and SS
Integer, Parameter :: n_fix=3      !Fixed productivity shock (determined at entry into the labor force)
Integer, Parameter :: n_hc_ret=3   !human capital categories at 64
Integer, Parameter :: n_zt=3       !Transitory shocks

Integer, Parameter :: n_type4 = 3 ! 1=single, 2=married, spouse not working, 3=married, spouse working


! leisure
Real (Kind=dd), dimension (n_e,n_o,n_h,n_type2) :: leis ! leisure 

Real (Kind=dd), parameter ::  hrs_ft =0.4d0
Real (Kind=dd), parameter ::  hrs_pt =0.2d0
Real (Kind=dd), dimension (n_o) :: hrs_offer

!Shocks to HC - we used to have shocks to human capital but no longer. 
Integer, Parameter :: n_zhc=1


 !assets
Real (Kind=dd), dimension (n_as, n_type1,n_age) :: as ! Grid for assets
 ! sick days
Integer, Parameter :: n_MEcat=2  ! 1= regular, 2=catastrophic

Real (Kind=dd), dimension (1:n_ret-1) ::max_age_HC



!the probability of each jMEcat
Real (Kind=dd), dimension (n_MEcat) :: Prob_MEcat 
!the probability of DI=1 and DI=2 - note it's implicit this is always conditional on poor health
Real (Kind=dd), dimension (n_e,n_DI) :: p_DI 

!Preferences
Real (Kind=dd) :: cost_death
Real (Kind=dd) :: vl               !Value of life
Real (Kind=dd) :: sigma
Real (Kind=dd) :: alpha
Real (Kind=dd) :: gamma
Real (Kind=dd), dimension(3,n_o) :: eta ! the disutility cost of not paying bill and getting treated - it has 3 values, set to 0 if treat and pay or if not treat. 123. 2 is the one that means treat, not pay.
Real (Kind=dd), dimension(n_e) :: beta_hat         ! discount rate
! bequest parameters
Real (Kind=dd) :: theta_beq
Real (Kind=dd) :: k_beq
Real (Kind=dd) :: sig_beq
Real (Kind=dd), dimension(n_e,n_age) :: equiv

!Initial distribution of H and R
Real (Kind=dd), dimension(n_e,n_h,n_ht) :: In_h
Real (Kind=dd), dimension(n_e,n_r) :: In_r
Real (Kind=dd), dimension(n_e,n_h,2) :: In_h_ht ! these depend on the latent health type
Real (Kind=dd), dimension(n_e,n_r,2) :: In_r_ht
Real (Kind=dd), dimension(n_type1) :: In_type1 !Initial distribution of educ, latent health types and skill types
Real (Kind=dd), dimension(n_e,n_fix) :: In_ht ! probability of latent health type=1 for each educ and latent skill group. ht=1 is good
Real (Kind=dd), dimension(n_e,n_h) :: In_mar ! initial dist'n of married

!Transitions for H
Real (Kind=dd), dimension(n_h,  n_h,n_e,n_ht, n_age, n_type2,2,4):: Tp_h  !Transition probability matrix for health. The second last argument is 1 or 2: 2 is get treated, 1 is not get treated.; the last one is the category for medical charges 1-4 (this no longer plays a role in the final version)

Real (Kind=dd), dimension(n_h, n_h, n_e, 2, n_age, n_dp, n_du, 1:5):: trprob_h ! this is an intermediate matrix
!Survival probabilities
Real (Kind=dd), dimension(n_h,n_e,n_mar,n_age) :: p_surv
!Transitions for R
Real (Kind=dd), dimension(n_r,n_r,n_age, n_h) :: p_risk
!Probabilities of Health shocks
Real (Kind=dd), dimension(n_e,n_type2, n_h, n_r, n_age) :: shocks_risk
!Medical expenditures
Real (Kind=dd), dimension(n_type2, n_h, n_age, n_MEcat,n_o) :: oop 
Real (Kind=dd), dimension(n_age,n_e, n_type4,n_o) :: oop_spouse
Real (Kind=dd), dimension(n_type2, n_h, n_ret-1, n_MEcat) :: Charges ! these don't depend on insurance. 


!Hours worked
Real (Kind=dd), dimension(n_e, n_h,n_type2) :: phi   ! this give the number of sick days given health and health shocks, and determines hours worked. 

!Leisure cost of being ill for non-workers, including retirees
Real (Kind=dd), dimension(n_h,n_type2) :: phi_nw ! phi non-workers.  

!Leisure cost of not working FT when the wife works
Real (Kind=dd), dimension(n_e,n_o,2) :: leis_mar

! OTHER PARAMETERS
Real (Kind=dd) :: interest         !Interest rate
Real (Kind=dd) :: taxc             !Consumption tax
Real (Kind=dd) :: taxc_hi          !Additional Consumption tax needed to balance the budget when we give public health insurance to <65. this tax is imposed only on those <65
Real (Kind=dd) :: tau_ss           !Tax for social security 
Real (Kind=dd) :: tau_med          !Medicare tax   
Real (Kind=dd), dimension(2) ::  tax_lambda        ! Parameter in tax function, depends on marital status
Real (Kind=dd), dimension(2) ::  tax_tau        ! Parameter in tax function, depends on marital status
Real (Kind=dd), dimension(n_age,n_mar,n_e, n_h) :: cons_floor,  cons_floor_at ! this is to read the cons floor for all educ groups 
Real (Kind=dd), dimension(n_e) :: c_floor_adjust_mar ! this parameter adjust the consumption floor of the married.

Real (Kind=dd) :: yhat             !Maximum taxable earnings  for social security
Real (Kind=dd) :: penalty          !A very low number to guarantee people consume positive amounts and do not borrow
Real (Kind=dd), dimension(n_e) ::  p_e   !Proportion in each education group
Real (Kind=dd), dimension(n_hc_ret, n_e, n_fix) ::  pen   !Retirement Income    (social security) pen(jhc_ret, jfix, je) ! the SS income of the spouse is added separately, so this here does not depend on marital status


Real (Kind=dd), dimension(n_o,n_type4) :: prem_ephi        ! ESHI premium (employee share only)
Real (Kind=dd), dimension(2) :: prem_mcare       ! Medicare premium (part B) - paid by those over 65. 1= for singles, 2=for married (this is 2 x singles)

!Wages  
Real (Kind=dd), dimension (n_e) ::  varzfix, stdzfix   , varzt, stdzt , rho, stdinno , varinno, stdze  !variance and sd of the fixed and transitory wage shocks
!Coefficients determining the deterministic compoenent of wages
Real (Kind=dd), dimension (n_e) ::	  b0
Real (Kind=dd), dimension (n_e) ::	  b1 ! HC 
Real (Kind=dd), dimension (n_e) ::	  b2 ! HC^2
Real (Kind=dd), dimension (n_e) ::	  b3 ! HC^3
Real (Kind=dd), dimension (n_e) ::	  b4 ! H=avg 
Real (Kind=dd), dimension (n_e) ::	  b5 ! H=good 
Real (Kind=dd), dimension (n_e) ::	  b6 ! not employed last year

Real (Kind=dd), dimension (n_e) ::	 PT_penalty
Real (Kind=dd), dimension (n_o, n_e) :: wage_penalty 
Real (Kind=dd) :: delta
Real (Kind=dd) :: delta_hc
Real (Kind=dd), dimension (n_e) :: delta_hc_read
Real (Kind=dd), dimension (n_ret) :: ws ! this is a vector of ones, except in experiments where we increase wages at various ages for everyone by say 20%


Real (Kind=dd), dimension (n_e,n_zt,2) :: p_zt             ! Probabilities of transitory shocks.  For the last argument, 1= not employed last year, and 2= employed last year. If employed last year, transitory shocks have mean zero. but if not employed last year, the mean is lower and we use beta(6) in the wage funtion which tells us how much lower
Real (Kind=dd), dimension (n_e,n_zt) :: zt               ! Transitory shocks
Real (Kind=dd), dimension (n_e,n_fix) :: p_fix           ! Probabilities of the fixed productivity type
Real (Kind=dd), dimension (n_e,n_fix) :: zfix            ! The individual fixed effects
Real (Kind=dd), dimension (n_e, 0:n_hc, n_h,n_o) :: zd_sim       ! The deterministic component of z
Real (Kind=dd), dimension (n_e, 0:n_hc, n_h) :: zd       ! The deterministic component of z

Real (Kind=dd), dimension (0:n_hc,n_h,n_e,n_fix,n_zt,n_o) :: z_sim ! in the simulation, we can let z depend on lagged o. 
Real (Kind=dd), dimension (0:n_hc,n_h,n_e,n_fix,n_zt) :: z ! Efficiency units
Real (Kind=dd), dimension (0:n_hc,n_h,n_e,n_fix,n_zt,n_o)  :: base_earn  ! base earnings 

!Shocks to HC - we no longer have these in the final version. 
Real (Kind=dd), dimension (n_e,n_o,n_zhc) :: p_zhc          ! Probabilities of the shocks to human capital
Real (Kind=dd), dimension (n_zhc) :: zhc            ! the shocks to human capital
Real (Kind=dd), dimension (n_e) :: stdzhc               ! standard deviation of the shocks to hc
!Employment offers
Real (Kind=dd), dimension(n_o,n_o,n_e,n_ret-1) :: Pr_o_i ! The probability of each wage offer "o" 
Real (Kind=dd), dimension(n_o,n_e) :: Pr_o_25    ! Initial probablity at 25
Real (Kind=dd), dimension (n_e,2) :: delta_o ! the linear trend determining the increase in the probability of getting no offer with age
Real (Kind=dd), dimension (n_e,6) :: param_o_trans ! 6 parameters per education group that determine prob of insurance and of PT or FT conditional on past states. 

!OTHERS
Real (Kind=dd) :: y_bar                       !This is a cap on income taxes- pay taxes only on income up to 2.5 times average income
Real (Kind=dd), dimension (n_h, n_type2, n_age) :: beta   !Actual discount factor that takes into account survival
Real (Kind=dd), dimension (n_type1) :: n_samp  !How many individuals we are simulating by type.


!RELATED TO THE GRID FOR AGE AND HUMAN CAPITAL
Real (Kind=dd), dimension (n_hc_grid, n_ret-1) :: xfn, agex
Integer, dimension (n_ret-1) :: hk_gp ! this function gives the number of hk grid points used at every age.  
    

!income group thresholds
  Real (Kind=dd), dimension (n_inc-1) :: INC_TS

! disutility of work
Real (Kind=dd), dimension (n_e,n_h)::  FT_fc ,   PT_fc

    integer, parameter:: dbl = kind(1d0)   
    real(dbl), parameter:: pi = 3.14159265358979d0
    character(1), parameter:: tab = char(9)
    
Real (Kind=dd), dimension (n_mar,n_mar, n_e,n_age,n_h,n_inc,n_o) :: Tp_mar   !Transition probabilities of productivity shocks. ! M',M,je,jage,jh,jinc,jo
Real (Kind=dd), dimension (n_age,n_e,n_h,n_type4,n_fix) :: inc_spouse  ! this can include the social security income of those retired
Real (Kind=dd), dimension (n_ret-1,n_e,n_h,n_os,n_fix) :: prob_os ! probability spouse works

Real (Kind=dd), dimension (n_e,n_fix) :: prob_os_skill
Real (Kind=dd), dimension (n_e,n_fix,2:3) :: inc_spouse_skill ! the last one is for jtype4=2 and jtype4=3 (spouse does not work and spouse works)

! for R
CHARACTER(80) :: flname2
Real (Kind=dd), dimension (7) :: param_r


! for H:
Real (Kind=dd), dimension (2) :: param_h_cutoff_A, param_h_cutoff_B
Real (Kind=dd), dimension (14) :: param_h

!this will be used both in VF and simulation. convenient to construct this. 
Real (Kind=dd), dimension (5,n_ret-1, n_o,n_e,n_ht,n_type3,n_type2,n_o,n_type3,n_zhc) :: prob_s_treat_new

!probability of reporting shocks and R if not treated
Real (Kind=dd), dimension (1:n_h,3,2) :: neu_shocks ! the second argument is for the 3 shocks. 1=dp, 2=du, 3=s.  last argument is for treat or not treat
Real (Kind=dd), dimension (n_o) :: neu_R ! for convenience, we have it as function of jo. But only insurance matters, i.e., 1,2,4 vs 3,5

! we discretize medical charges for the purpose of H transitions when untreated. 4 categories, so we need 3 thresholds - no longer used
Real (Kind=dd), dimension (3) :: MC_TS
! we discretize human capital at age 64 into categories for the purpose of determining SS when retired. 5 categories, so we need 4 thresholds
Real (Kind=dd), dimension (2,n_e) :: hc_TS
     
Real :: time1, time2, time3, time4, time5, time
    END MODULE PARAMETERS
    
    

